import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class LoginPage extends StatefulWidget {
  LoginPage({Key key}) : super(key: key);

  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  TextEditingController _usernameController = TextEditingController();
  bool _isObscurePassword = true;
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomPadding: false,
        body: Container(
          width: MediaQuery.of(context).size.width,
          child: Column(
            children: <Widget>[
              SizedBox(height: 100),
              Padding(
                child: ClipOval(
                  child: Container(
                    height: 150,
                    width: 150,
                    child: Center(
                      child: Text("GONOVO"),
                    ),
                    color: Colors.green,
                  ),
                ),
                padding: EdgeInsets.all(40),
              ),
              SizedBox(
                height: 40,
              ),
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 20),
                child: TextField(
                  controller: _usernameController,
                  autofocus: true,
                  onChanged: (v) {},
                  decoration: InputDecoration(
                      suffixIcon: (_usernameController.text.length > 0)
                          ? IconButton(
                              //清空输入框
                              icon: Icon(Icons.highlight_off),
                              onPressed: () {
                                _usernameController.clear();
                              })
                          : null,
                      labelText: "用户名",
                      labelStyle: TextStyle(color: Colors.grey)),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20.0),
                child: TextField(
                  obscureText: _isObscurePassword,
                  decoration: InputDecoration(
                      suffixIcon: IconButton(
                        icon: Icon(
                          Icons.remove_red_eye,
                          color: Colors.grey,
                        ),
                        onPressed: () {
                          setState(() {
                            _isObscurePassword =
                                (_isObscurePassword == false) ? true : false;
                          });
                        },
                      ),
                      labelText: "密码",
                      labelStyle: TextStyle(color: Colors.grey)),
                ),
              ),
              SizedBox(height: 40),
              Container(
                width: MediaQuery.of(context).size.width - 40,
                child: FlatButton(
                  padding: EdgeInsets.symmetric(vertical: 10),
                  child: Text("登录"),
                  textColor: Colors.white,
                  onPressed: () {
                    print(_usernameController.text);
                    Navigator.of(context).pushNamedAndRemoveUntil('/',(route) => route == null);
                  },
                  color: Colors.green,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(45)),
                ),
              ),
            ],
          ),
        ));
  }
}
